import React, {Component} from 'react';
import {
    Image,
    StyleSheet,
    Text,
    View,
    TextInput,
    TouchableOpacity,
    StatusBar,
} from 'react-native';
import * as AsyncStorage from "react-native/Libraries/Storage/AsyncStorage";


export const param = {
    userId: 'userId',
    username: 'userName',
    userRole: 'userRole',
};
/**
 * 提供数据持久化存储 SharedPreference
 */
export default class ASUtil extends Component {

    static setParam(key, value) {
        try {
            AsyncStorage.setItem(key, value + "", function (err) {
                if (err)
                    this.console.error("ASUtil error:  " + err);
            });
        }
        catch (Err) {
            console.error(Err);
        }
    }

    /**
     * @param key 键
     * @param defalutValue 默认值
     * @param that 上下文
     */
    static getParam(key, defalutValue, that) {
        AsyncStorage.getItem(key, function (err, result) {
            if (err) {
                this.console.error("ASUtil error:  " + err);
                return defalutValue;
            } else {
                // _that.setState({text:result});
                return result;
            }
        });
    }
}